package com.punch.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punch.common.dto.course.AdminEditClassDTO;
import com.punch.common.dto.course.ApplyCourseDTO;
import com.punch.common.dto.course.ClassDTO;
import com.punch.common.dto.course.ClassSaveOrUpdateDTO;
import com.punch.common.dto.user.user.RedisUserDTO;
import com.punch.common.enums.course.ClassStatusEnum;
import com.punch.common.enums.course.GradeEnum;
import com.punch.common.enums.course.WeekEnum;
import com.punch.common.enums.user.role.UserRoleEnum;
import com.punch.common.exception.BusinessException;
import com.punch.common.feign.FeignAreaService;
import com.punch.common.feign.FeignOrderService;
import com.punch.common.page.PageInfo;
import com.punch.common.redis.lock.RedissonDistributedLock;
import com.punch.common.redis.utils.UserUtil;
import com.punch.common.tools.BasePage;
import com.punch.common.utils.BigDecimalUtil;
import com.punch.common.vo.course.classes.ClassPageVO;
import com.punch.common.vo.course.classes.ClassVO;
import com.punch.course.asyn.CourseAsync;
import com.punch.course.exception.CourseExceptionEnum;
import com.punch.course.mapper.CourseClassMapper;
import com.punch.course.model.CourseClass;
import com.punch.course.model.CourseClassGoods;
import com.punch.course.model.CourseSchool;
import com.punch.course.query.ClassQueryInfo;
import com.punch.course.service.CourseClassGoodsService;
import com.punch.course.service.CourseClassService;
import com.punch.course.service.CourseSchoolService;
import com.punch.course.util.CourseClassUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * 课程班级表 服务实现类
 * </p>
 *
 * @author wjj
 * @since 2020-12-01
 */
@Service
@Slf4j
public class CourseClassServiceImpl extends ServiceImpl<CourseClassMapper, CourseClass> implements CourseClassService {

    @Resource
    private FeignAreaService feignAreaService;

    @Resource
    private RedissonDistributedLock redissonDistributedLock;

    @Resource
    private CourseSchoolService courseSchoolService;

    @Autowired
    @Lazy
    private CourseAsync courseAsync;

    @Resource
    private FeignOrderService feignOrderService;

    @Resource
    private CourseClassGoodsService courseClassGoodsService;

    /**
     * 条件分页查询班级列表
     *
     * @param classQueryInfo 查询条件
     * @return PageInfo<ClassPageVO>
     */
    @Override
    public PageInfo<ClassPageVO> listClass(ClassQueryInfo classQueryInfo) {
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        //如果当前用户是机构,只查询与该机构关联的课程下的班级
        if (loginUser.getRoleId() == UserRoleEnum.ORGAN.getCode()) {
            classQueryInfo.setCreateId(loginUser.getUserId());
        }
        //如果当前用户是学校,只查询与该机构关联的课程下的班级
        if (loginUser.getRoleId() == UserRoleEnum.SCHOOL.getCode()) {
            classQueryInfo.setSchoolId(loginUser.getUserId());
        }
        classQueryInfo.setCurrentRoleId(loginUser.getRoleId());
        classQueryInfo.setCurrentAreaId(loginUser.getAreaId());
        return BasePage.queryBasePage(classQueryInfo, params -> this.getBaseMapper().queryCount(params),
                params -> {
                    List<ClassPageVO> retList = this.getBaseMapper().queryList(params);
                    retList.forEach(classPageVO -> classPageVO.setCourseTime(CourseClassUtil.getIntWeekToString(classPageVO.getCourseWeek(), classPageVO.getClassTime())));
                    return retList;
                });
    }

    /**
     * 查询班级详情
     *
     * @param classId 课程班级id
     * @return ClassVO
     */
    @Override
    public ClassVO getClasses(Long classId) {
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        ClassVO classVO = new ClassVO();
        BeanUtils.copyProperties(courseClassEX, classVO);
        QueryWrapper<CourseSchool> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CourseSchool::getClassId, classId);
        CourseSchool courseSchoolEX = courseSchoolService.getOne(queryWrapper);
        Optional.ofNullable(courseSchoolEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        BeanUtils.copyProperties(courseSchoolEX, classVO);
        //适用年级 courseGrade
        if (StringUtils.isNotEmpty(courseSchoolEX.getCourseGrade())) {
            String[] courseGradeArray = courseSchoolEX.getCourseGrade().split(",");
            List<Integer> courseGradeList = new ArrayList<>();
            List<String> courseGradeNameList = new ArrayList<>();
            for (String courseGrade : courseGradeArray) {
                courseGradeList.add(Integer.valueOf(courseGrade));
                courseGradeNameList.add(GradeEnum.getName(Integer.valueOf(courseGrade)));
            }
            classVO.setCourseGrade(courseGradeList);
            classVO.setCourseGradeName(courseGradeNameList);
        }
        //上课周期 courseWeek 单独处理
        if (StringUtils.isNotEmpty(courseSchoolEX.getCourseWeek())) {
            String[] courseWeekArray = courseSchoolEX.getCourseWeek().split(",");
            List<Integer> courseWeekList = new ArrayList<>();
            List<String> courseWeekNameList = new ArrayList<>();
            for (String courseWeek : courseWeekArray) {
                courseWeekList.add(Integer.valueOf(courseWeek));
                courseWeekNameList.add(WeekEnum.getName(Integer.valueOf(courseWeek)));
            }
            classVO.setCourseWeek(courseWeekList);
            classVO.setCourseWeekName(courseWeekNameList);
        }
        //设置金额
        classVO.setCourseHourPriceShow(BigDecimalUtil.getMoneyBigDecimal(courseSchoolEX.getCourseHourPrice()));
        classVO.setClassId(classId);
        //设置教师是否可以修改,只有当前登录用户与班级创建用户一致时才能修改
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getUserId().equals(courseClassEX.getCreateId())) {
            classVO.setTeacherUpdateFlag(1);
        } else {
            classVO.setTeacherUpdateFlag(0);
        }
        //运营可以修改教师
        if (loginUser.getRoleId() == UserRoleEnum.ADMIN.getCode() || loginUser.getRoleId() == UserRoleEnum.MANAGER.getCode()) {
            classVO.setTeacherUpdateFlag(1);
        }
        //获取教具信息
        if (courseSchoolEX.getGoodsFlag() == 1) {
            classVO.setGoodsFlag(1);
            QueryWrapper<CourseClassGoods> courseClassGoodsQueryWrapper = new QueryWrapper<>();
            courseClassGoodsQueryWrapper.lambda().eq(CourseClassGoods::getClassId, classId);
            CourseClassGoods courseClassGoodsEX = courseClassGoodsService.getOne(courseClassGoodsQueryWrapper);
            Optional.ofNullable(courseClassGoodsEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.GOODS_NOT_EXIST));
            classVO.setGoodsId(courseClassGoodsEX.getGoodsId());
            classVO.setGoodsName(courseClassGoodsEX.getGoodsName());
            classVO.setGoodsPriceShow(BigDecimalUtil.getMoneyBigDecimal(courseClassGoodsEX.getGoodsPrice()));
        }

        return classVO;
    }

    /**
     * 新增课程班级
     *
     * @param classSaveOrUpdateDTO 班级新增/修改表单
     * @return 主键id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long saveClass(ClassSaveOrUpdateDTO classSaveOrUpdateDTO) {
        CourseClass courseClass = new CourseClass();
        courseClass.setClassName(classSaveOrUpdateDTO.getClassName());
        courseClass.setTeacherId(classSaveOrUpdateDTO.getTeacherId());
        courseClass.setTeacherName(classSaveOrUpdateDTO.getTeacherName());
        //获取地区名称  --从当前用户带
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        Long userId = loginUser.getUserId();
        String username = loginUser.getUsername();
        courseClass.setCreateId(userId);
        courseClass.setCreateName(username);
        Integer currentUserAreaId = loginUser.getAreaId();
        courseClass.setAreaId(currentUserAreaId);
        String parentIds = feignAreaService.getParentIds(currentUserAreaId);
        courseClass.setAllAreaId(parentIds + "," + currentUserAreaId);
        courseClass.setAreaName(loginUser.getAreaName());
        //学校自己创建的班级不存在申请开班
        if (loginUser.getRoleId() == UserRoleEnum.SCHOOL.getCode()) {
            courseClass.setSchoolId(userId);
            courseClass.setSchoolName(username);
            courseClass.setType(1);
            courseClass.setClassStatus(ClassStatusEnum.TO_RELEASE.getCode());
        }
        if (!save(courseClass)) {
            throw new BusinessException(CourseExceptionEnum.CLASS_SAVE_FAIL);
        }
        Long classId = courseClass.getId();
        //课程授课学校表
        Long courseId = courseSchoolService.saveCourseSchool(classSaveOrUpdateDTO, classId, userId, username);
        courseClass.setCourseId(courseId);
        updateById(courseClass);
        courseClass = null;
        loginUser = null;
        return classId;
    }

    /**
     * 修改班级信息
     *
     * @param classId              班级id
     * @param classSaveOrUpdateDTO 班级新增/修改表单
     * @return 主键id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateUnReleaseClass(Long classId, ClassSaveOrUpdateDTO classSaveOrUpdateDTO) {
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //只有待发布状态才能修改
        Integer classStatus = courseClassEX.getClassStatus();
        if (classStatus != ClassStatusEnum.TO_APPLY.getCode() && classStatus != ClassStatusEnum.REFUSE.getCode()) {
            throw new BusinessException(CourseExceptionEnum.CLASS_EXAMINE_ILLEGALA_FIAL);
        }
        CourseClass courseClass = new CourseClass();
        courseClass.setClassName(classSaveOrUpdateDTO.getClassName());
        courseClass.setTeacherId(classSaveOrUpdateDTO.getTeacherId());
        courseClass.setTeacherName(classSaveOrUpdateDTO.getTeacherName());
        courseClass.setId(classId);
        updateById(courseClass);
        //课程授课学校表
        courseSchoolService.updateUnReleaseCourseSchool(classSaveOrUpdateDTO, classId);
    }

    /**
     * 删除班级信息
     *
     * @param classId 班级id
     * @return 删除提示消息
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteClass(Long classId) {
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //1-待发布(学校)
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getRoleId() == UserRoleEnum.SCHOOL.getCode() && ClassStatusEnum.TO_RELEASE.getCode() != courseClassEX.getClassStatus()) {
            throw new BusinessException(CourseExceptionEnum.COURSE_DELETE_STATUS_ERROR);
        }
        //只有0-待申请(机构),6-拒绝(机构)才能删除
        if (loginUser.getRoleId() == UserRoleEnum.ORGAN.getCode() &&
                (ClassStatusEnum.TO_APPLY.getCode() != courseClassEX.getClassStatus() && ClassStatusEnum.REFUSE.getCode() != courseClassEX.getClassStatus())) {
            throw new BusinessException(CourseExceptionEnum.COURSE_DELETE_STATUS_ERROR);
        }
        removeById(classId);
        //删除课程信息
        UpdateWrapper<CourseSchool> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().eq(CourseSchool::getClassId, classId);
        courseSchoolService.remove(updateWrapper);
        //删除课程教具
        UpdateWrapper<CourseClassGoods> goodsUpdateWrapper = new UpdateWrapper<>();
        goodsUpdateWrapper.lambda().eq(CourseClassGoods::getClassId, classId);
        courseClassGoodsService.remove(goodsUpdateWrapper);
    }

    /**
     * 机构申请开班
     *
     * @param applyCourseDTO 开班表单
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void applySchoolCourse(ApplyCourseDTO applyCourseDTO) {
        //只有机构才能进行申请开班
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getRoleId() != UserRoleEnum.ORGAN.getCode()) {
            throw new BusinessException(CourseExceptionEnum.ONLY_ORG_APPLY_SCHOOL);
        }
        Long classId = applyCourseDTO.getClassId();
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //只有待申请/拒绝状态才能进行申请
        if (ClassStatusEnum.TO_APPLY.getCode() != courseClassEX.getClassStatus() && ClassStatusEnum.REFUSE.getCode() != courseClassEX.getClassStatus()) {
            throw new BusinessException(CourseExceptionEnum.CLASS_STATUS_ERROR);
        }
        CourseClass courseClass = new CourseClass();
        courseClass.setId(classId);
        courseClass.setSchoolId(applyCourseDTO.getSchoolId());
        courseClass.setSchoolName(applyCourseDTO.getSchoolName());
        courseClass.setClassStatus(ClassStatusEnum.TO_RELEASE.getCode());
        updateById(courseClass);
    }

    /**
     * 机构取消申请开班
     *
     * @param classId 班级id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void applySchoolCourseCancel(Long classId) {
        //只有机构才能进行申请开班
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getRoleId() != UserRoleEnum.ORGAN.getCode()) {
            throw new BusinessException(CourseExceptionEnum.ONLY_ORG_APPLY_SCHOOL);
        }
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //只有待申请状态才能进行申请
        if (ClassStatusEnum.TO_RELEASE.getCode() != courseClassEX.getClassStatus()) {
            throw new BusinessException(CourseExceptionEnum.CLASS_STATUS_ERROR);
        }
        CourseClass courseClass = new CourseClass();
        courseClass.setId(classId);
        courseClass.setSchoolId(0L);
        courseClass.setSchoolName("");
        courseClass.setClassStatus(ClassStatusEnum.TO_APPLY.getCode());
        updateById(courseClass);
    }

    /**
     * 发布班级
     *
     * @param classId  班级id
     * @param classDTO 班级发布
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void releaseClass(Long classId, ClassDTO classDTO) {
        validateClass(classDTO);
        //只有发布状态才能发布
        CourseClass courseClassEX = getById(classId);
        Integer classStatus = courseClassEX.getClassStatus();
        if (classStatus != ClassStatusEnum.TO_RELEASE.getCode()) {
            throw new BusinessException(CourseExceptionEnum.CLASS_EXAMINE_ILLEGALA_FIAL);
        }
        CourseClass courseClass = new CourseClass();
        BeanUtils.copyProperties(classDTO, courseClass);
        courseClass.setPlanCourseCount(classDTO.getCourseHourCount());
        courseClass.setClassStatus(ClassStatusEnum.TO_SIGN.getCode());
        courseClass.setId(classId);
        //计算真正开课时间与课时数
        Map<String, Object> openDateAndCourseMap = CourseClassUtil.getOpenDateAndCourseCount(classDTO.getPlanOpenDate(), classDTO.getCourseWeek(), classDTO.getCourseHourCount());
        LocalDate actualOpenDate = (LocalDate) openDateAndCourseMap.get("actualOpenDate");//真正开班日期
        courseClass.setActualOpenDate(actualOpenDate);
        updateById(courseClass);
        //课程授课学校表
        Integer courseHourCount = (Integer) openDateAndCourseMap.get("courseHourCount");//真正课时数
        classDTO.setCourseHourCount(courseHourCount);
        courseSchoolService.updateReleaseCourseSchool(classDTO, classId);
        //插入开始报名的定时任务
        courseAsync.toSignUpTimeTask(classId, classDTO.getSignUpStartTime());
    }

    /**
     * 取消报名
     *
     * @param classId 班级id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void signUpCancel(Long classId) {
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //只有学校才能取消报名
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getRoleId() != UserRoleEnum.SCHOOL.getCode()) {
            throw new BusinessException(CourseExceptionEnum.ONLY_SCHOOL_CANCEL_SIGN_UP);
        }
        Integer classStatus = courseClassEX.getClassStatus();
        //待报名,报名中状态才能取消
        if (ClassStatusEnum.TO_SIGN.getCode() != classStatus && ClassStatusEnum.SIGN_IN.getCode() != classStatus) {
            throw new BusinessException(CourseExceptionEnum.CLASS_EXAMINE_ILLEGALA_FIAL);
        }
        CourseClass courseClass = new CourseClass();
        courseClass.setClassStatus(ClassStatusEnum.TO_RELEASE.getCode());
        courseClass.setId(classId);
        updateById(courseClass);
        //报名中取消--涉及到订单进行退款
        if (ClassStatusEnum.SIGN_IN.getCode() == classStatus) {
            // TODO: 2020/12/2
        }
        //异步修改课程数,定时任务
        courseAsync.removeTimeTaskAndUpdateCourse(classId, courseClassEX.getPlanCourseCount());
    }

    /**
     * 拒绝申请
     *
     * @param classId 班级id
     */
    @Override
    public void refuseApply(Long classId) {
        //只有学校才能拒绝申请
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getRoleId() != UserRoleEnum.SCHOOL.getCode()) {
            throw new BusinessException(CourseExceptionEnum.ONLY_SCHOOL_CANCEL_SIGN_UP);
        }
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //待发布的才能拒绝
        if (ClassStatusEnum.TO_RELEASE.getCode() != courseClassEX.getClassStatus()) {
            throw new BusinessException(CourseExceptionEnum.CLASS_EXAMINE_ILLEGALA_FIAL);
        }
        CourseClass courseClass = new CourseClass();
        courseClass.setId(classId);
        courseClass.setClassStatus(ClassStatusEnum.REFUSE.getCode());
        updateById(courseClass);
    }

    /**
     * 运营修改班级
     *
     * @param classId           班级id
     * @param adminEditClassDTO 运营修改班级dto
     * @return 主键id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void adminEditClass(Long classId, AdminEditClassDTO adminEditClassDTO) {
        CourseClass courseClassEX = getById(classId);
        Optional.ofNullable(courseClassEX).orElseThrow(() -> new BusinessException(CourseExceptionEnum.CLASS_DETAIL_FAIL_NULL));
        //待报名修改
        switch (courseClassEX.getClassStatus()) {
            case 2:
                //待报名修改
                toSignUpdate(courseClassEX, adminEditClassDTO);
                break;
            case 3:
                //报名中修改
                signInUpdate(courseClassEX, adminEditClassDTO);
                break;
            case 4:
                //已开班修改
                openClassUpdate(courseClassEX, adminEditClassDTO);
                break;
            default:
                throw new BusinessException(CourseExceptionEnum.CLASS_EXAMINE_ILLEGALA_FIAL);
        }
    }

    /**
     * 报名修改班级课程的报名人数
     *
     * @param courseClassId 班级课程id
     */
    @Override
    public Boolean updateSignUpNumber(Long courseClassId) {
        // 需要添加锁
        String key = "classId:sign-up:" + courseClassId;
        RLock lock = null;
        try {
            lock = redissonDistributedLock.tryLock(key, 5, TimeUnit.SECONDS);
            if (lock != null) {
                //执行业务逻辑
                return getBaseMapper().updateSignUpNumberById(courseClassId);
            } else {
                log.info("Redisson分布式锁没有获得锁:{},ThreadName:{}", key, Thread.currentThread().getName());
                return false;
            }
        } catch (InterruptedException e) {
            log.error("Redisson获取分布式锁异常,异常信息:{}", e.getMessage());
        } finally {
            //如果演示的话需要注释该代码;实际应该放开
            redissonDistributedLock.unlock(lock);
            log.info("Redisson分布式锁释放锁:{},ThreadName :{}", key, Thread.currentThread().getName());
        }
        return false;
    }

    /**
     * 班级验证
     *
     * @param classDTO 班级信息表单
     */
    private void validateClass(ClassDTO classDTO) {
        //只有学校才能进行发布班级
        RedisUserDTO loginUser = UserUtil.getLoginUser();
        if (loginUser.getRoleId() != UserRoleEnum.SCHOOL.getCode()) {
            throw new BusinessException(CourseExceptionEnum.ONLY_SCHOOL_RELEASE);
        }
        //开班时间>报名截止时间
        if (classDTO.getPlanOpenDate().compareTo(classDTO.getSignUpEndTime().toLocalDate()) < 0) {
            throw new BusinessException(CourseExceptionEnum.CLASS_OPEN_DATE_LESS_THEN_REGIST_END_TIME);
        }
        //报名截止时间>报名开始时间
        if (classDTO.getSignUpEndTime().compareTo(classDTO.getSignUpStartTime()) < 0) {
            throw new BusinessException(CourseExceptionEnum.REGISTENDTIME_LESS_THEN_REGISTSTARTTIME);
        }
    }


    /**
     * 待报名修改
     *
     * @param courseClassEX     班级
     * @param adminEditClassDTO 运营修改表单
     */
    private void toSignUpdate(CourseClass courseClassEX, AdminEditClassDTO adminEditClassDTO) {
        Long classId = courseClassEX.getId();
        CourseClass courseClass = new CourseClass();
        BeanUtils.copyProperties(adminEditClassDTO, courseClass);
        courseClass.setId(classId);
        updateById(courseClass);
        //课程授课学校表
        ClassDTO classDTO = new ClassDTO();
        BeanUtils.copyProperties(adminEditClassDTO, classDTO);
        courseSchoolService.updateReleaseCourseSchool(classDTO, classId);
        //如果班级开始报名时间发生变化
        if (courseClassEX.getSignUpStartTime().compareTo(adminEditClassDTO.getSignUpStartTime()) != 0) {
            courseAsync.toSignUpTimeTask(classId, classDTO.getSignUpStartTime());
        }
    }

    /**
     * 报名中修改
     *
     * @param courseClassEX     班级
     * @param adminEditClassDTO 运营修改表单
     */
    private void signInUpdate(CourseClass courseClassEX, AdminEditClassDTO adminEditClassDTO) {
        //修改 开班时间 教师 教室 需要修改课程订单数据
        long classId = courseClassEX.getId();
        CourseClass courseClass = new CourseClass();
        BeanUtils.copyProperties(adminEditClassDTO, courseClass);
        courseClass.setId(classId);
        //课程授课学校表
        ClassDTO classDTO = new ClassDTO();
        BeanUtils.copyProperties(adminEditClassDTO, classDTO);
        //开班时间
        if (courseClassEX.getPlanOpenDate().compareTo(adminEditClassDTO.getPlanOpenDate()) != 0) {
            //获取真正的开班时间
            Integer planCourseCount = courseClassEX.getPlanCourseCount();
            Map<String, Object> openDateAndCourseMap = CourseClassUtil.getOpenDateAndCourseCount(adminEditClassDTO.getPlanOpenDate(), adminEditClassDTO.getCourseWeek(), planCourseCount);
            LocalDate actualOpenDate = (LocalDate) openDateAndCourseMap.get("actualOpenDate");//真正开班日期
            courseClass.setActualOpenDate(actualOpenDate);
            Integer courseHourCount = (Integer) openDateAndCourseMap.get("courseHourCount");//真正课时数
            classDTO.setCourseHourCount(courseHourCount);
            feignOrderService.feignUpdateCourseOrderOpenDate(classId, actualOpenDate);
        }
        courseSchoolService.updateReleaseCourseSchool(classDTO, classId);
        updateById(courseClass);
        //如果报名截止时间变化
        if (courseClassEX.getSignUpEndTime().compareTo(adminEditClassDTO.getSignUpEndTime()) != 0) {
            courseAsync.toOpenClassTimeTask(classId, adminEditClassDTO.getSignUpEndTime());
        }
        //教师
        if (!courseClassEX.getTeacherId().equals(adminEditClassDTO.getTeacherId())) {
            //需要修改课程订单教师
            feignOrderService.feignUpdateCourseOrderTeacher(classId, adminEditClassDTO.getTeacherName());
        }
        //教室
        if (!courseClassEX.getClassRoomId().equals(adminEditClassDTO.getClassRoomId())) {
            //需要修改课程订单教师
            feignOrderService.feignUpdateCourseOrderClassRoom(classId, adminEditClassDTO.getClassRoomName());
        }
    }

    /**
     * 已开班修改
     *
     * @param courseClassEX     班级
     * @param adminEditClassDTO 运营修改表单
     */
    private void openClassUpdate(CourseClass courseClassEX, AdminEditClassDTO adminEditClassDTO) {
        //只能修改老师
        long classId = courseClassEX.getId();
        if (!courseClassEX.getTeacherId().equals(adminEditClassDTO.getTeacherId())) {
            CourseClass courseClass = new CourseClass();
            courseClass.setId(classId);
            courseClass.setTeacherId(adminEditClassDTO.getTeacherId());
            courseClass.setTeacherName(adminEditClassDTO.getTeacherName());
            updateById(courseClass);
            //需要修改课程订单教师
            feignOrderService.feignUpdateCourseOrderTeacher(classId, adminEditClassDTO.getTeacherName());
        }

    }


}
